C51 COMPILER V9.60.0.0   MAIN                                                              03/13/2023 13:47:56 PAGE 1   


C51 COMPILER V9.60.0.0, COMPILATION OF MODULE MAIN
OBJECT MODULE PLACED IN .\Release\main.obj
COMPILER INVOKED BY: C:\Keil_v5\C51\BIN\C51.EXE main.c OPTIMIZE(0,SPEED) REGFILE(.\Release\Sample_DrvSPI_Master.ORC) BRO
                    -WSE INCDIR(..\..\..\..\C51SIS\C51;..\..\..\Include\Driver) DEBUG OBJECTEXTEND TABS(2) OBJECT(.\Release\main.obj)

line level    source

   1          /**************************************************************************//**
   2           * @file           main.c
   3           * @version        V1.0
   4           * $Revision:      1 $
   5           * $Date:          2017/01/04 $
   6           * @brief          Main function
   7           * @Author         Jeffrey Kang
   8           * @ContactInfo    chkang@esmt.com.tw
   9           *
  10           * @note
  11           *
  12           * Copyright (C) 1998 Elite Semiconductor Memory Technology Corp.
  13           * All rights reserved.
  14           *
  15           ******************************************************************************/
  16          
  17          
  18          #include <REG52.h>
  19          #include "system_FE81001.h"
  20          
  21          
  22          static volatile unsigned char xdata spi_data[5] = {0x01,0x02,0x03,0x04,0x05};
  23          static volatile unsigned char xdata spi_read_data[5] = {0};
  24          unsigned char int_stat; 
  25          unsigned char int_stat_1; 
  26          unsigned char int_stat_2; 
  27          unsigned char cnt = 0;
  28          
  29          /**
  30           * @brief       delay function
  31           *
  32           * @param       None
  33           *
  34           * @return      None
  35           *
  36           * @details     1. 
  37           */
  38          void delay (void)
  39          {
  40   1        unsigned int i;
  41   1        
  42   1        for( i = 0 ; i < 5 ; i++ ){}
  43   1      }
  44          
  45          
  46          /**
  47           * @brief       SPIISR function
  48           *
  49           * @param       None
  50           *
  51           * @return      None
  52           *
  53           * @details     1. 
  54           */
C51 COMPILER V9.60.0.0   MAIN                                                              03/13/2023 13:47:56 PAGE 2   

  55          const void SPIISR (void) interrupt ISR_SPI
  56          {
  57   1        int_stat = SPI->int_stat;
  58   1        
  59   1        PD->gpio_dout1 = ~PD->gpio_dout1;
  60   1        
  61   1        if ((int_stat & 0x10) == 0x10)
  62   1          SPI->int_stat |= 0x10;
  63   1        
  64   1        /* enable global interrupt */
  65   1        INTC->int_gmask = 0x01;
  66   1      }
  67          
  68          
  69          /**
  70           * @brief       SPIMasterTransmitConfig function
  71           *
  72           * @param       None
  73           *
  74           * @return      None
  75           *
  76           * @details     1. 
  77           */
  78          void SPIMasterTransmitConfig()
  79          {
  80   1      #if 0
                SPI->trans_fmt[0]    = 0x1F;       // DataMerge(1) = 0, 0, 0, MOSIBiDir(1) = 1, LSB(1) = 1, SlvMode(1) = 
             -1, CPOL(1) = 1, CPHA(1) = 1
                SPI->trans_fmt[1]    = 0x9F;       // AddrLen(2) = 2, 0, DataLen(5) = 0x1F
                SPI->trans_ctrl[0]   = 0xFF;       // RdTranCnt(8) = 0xFF
                SPI->trans_ctrl[1]   = 0xFF;       // WrTranCnt(4) = 15, TokenValue(1) = 1, DummyCnt(2) = 0 ,RdTranCnt(1)
             - = 1
                SPI->trans_ctrl[2]   = 0xFF;       // DualQuad(2) = 0, TokenEn(1) = 1, WrTranCnt(5) = 15
                SPI->trans_ctrl[3]   = 0x7F;       // 0, CmdEn(1) = 1, AddrEn(1) = 1, AddrFmt(1) = 0, TransMode(4) = 15
                SPI->spi_cmd         = 0x00;       //
                SPI->spi_adr[0]      = 0xFF;
                SPI->spi_adr[1]      = 0xFF;
                SPI->spi_adr[2]      = 0xFF;
                SPI->spi_dat         = 0xFF;
                SPI->spi_ctrl[0]     = 0x07;       // 0, 0, 0, TXDMAEN(1) = 0, RXDMAEN(1) = 0, TXFIFORST(1) = 1, RXFIFORS
             -T(1) = 1, SPIRST(1) = 1
                SPI->spi_ctrl[1]     = 0x1F;       // 0, 0, 0, RXTHRES(5) = 0x1F
                SPI->spi_ctrl[2]     = 0x1F;       // 0, 0, 0, TXTHRES(5) = 0x1F
                //spi_stat[0]                        // 0, 0, 0, 0, 0, 0, 0, SPIActive(1)
                //spi_stat[1]                        // RXFULL(1), RXEMPTY(1), 0, RXNUM(5)
                //spi_stat[2]                        // TXFULL(1), TXEMPTY(1), 0, TXNUM(5)
                SPI->int_en         = 0x3F;        // 0, 0, SlvCmdEn(1) = 1, EndIntEn(1) = 1, TXFIFOIntEn(1) = 1, RXFIFOI
             -ntEn(1) = 1, TXFIFOURIntEn(1) = 1, RXFIFOORIntEn(1) = 1
                //int_stat                           // 0, 0, SlvCmdEn(1), EndIntEn(1), TXFIFOIntEn(1), RXFIFOIntEn(1), T
             -XFIFOURIntEn(1), RXFIFOORIntEn(1)
                SPI->intf_timing[0] = 0xFF;        // SCLK_DIV(8) = 0xFF
                SPI->intf_timing[1] = 0xFF;        // 0, 0, CS2SCLK(2) = 3, CSHT(4) = 15
                SPI->slv_stat[0]    = 0xFF;        // USR_Status(8)
                SPI->slv_stat[1]    = 0xFF;        // USR_Status(8)
                SPI->slv_stat[2]    = 0x01;        // 0, 0, 0, 0, 0, UnderRun(1), OverRun(1), Ready(1) = 1
                //slv_rcvcnt[0]                      // RCnt(8)
                //slv_rcvcnt[1]                      // 0, 0, 0, 0, 0, 0, 0, RCnt(1)
                //slv_tsmcnt[0]                      // WCnt(8)
                //slv_tsmcnt[1]                      // 0, 0, 0, 0, 0, 0, 0, WCnt(1)
                //SPI->spi_cfg                       // 0, 0, RxFIFOSize(2), 0, 0, RxFIFOSize(2)
              #endif
 111   1        
C51 COMPILER V9.60.0.0   MAIN                                                              03/13/2023 13:47:56 PAGE 3   

 112   1        /* wait SPI transfer finished */
 113   1        while((SPI->spi_stat[0] & 0x01) == 0x01){}
 114   1        
 115   1        /* set SPI transfer format */
 116   1        SPI->trans_fmt[0] = 0x00;          // DataMerge(1) = 0, 0, 0, MOSIBiDir(1) = 0, LSB(1) = 0, SlvMode(1) = 
             -0, CPOL(1) = 0, CPHA(1) = 0
 117   1        SPI->trans_fmt[1] = 0x07;          // AddrLen(2) = 1 ((addrlen(u:bytes)-1)), 0, DataLen(5) = 0x07 ((datal
             -en(u:bits))-1)
 118   1        
 119   1        /* set SPI transfer control */
 120   1        SPI->trans_ctrl[0] = 0x00;         // RdTranCnt(8) = 0
 121   1        SPI->trans_ctrl[1] = 0x00;         // WrTranCnt(4) = 0 (1-byte data_), TokenValue(1) = 0, DummyCnt(2) = 0
             - ,RdTranCnt(1) = 0
 122   1        SPI->trans_ctrl[2] = 0x00;         // DualQuad(2) = 0, TokenEn(1) = 0, WrTranCnt(5) = 0
 123   1        SPI->trans_ctrl[3] = 0x01;         // 0, CmdEn(1) = 0, AddrEn(1) = 1, AddrFmt(1) = 0, TransMode(4) = 1 (w
             -rite only)
 124   1        
 125   1        /* set SPI control */
 126   1        SPI->spi_ctrl[0] = 0x07;           // 0, 0, 0, TXDMAEN(1) = 0, RXDMAEN(1) = 0, TXFIFORST(1) = 1, RXFIFORS
             -T(1) = 1, SPIRST(1) = 1
 127   1        SPI->spi_ctrl[1] = 0x00;           // 0, 0, 0, RXTHRES(5) = 0x00
 128   1        SPI->spi_ctrl[2] = 0x00;           // 0, 0, 0, TXTHRES(5) = 0x00
 129   1        
 130   1        /* set interrupt enable */
 131   1        //SPI->int_en = 0x14;                // 0, 0, SlvCmdEn(1) = 0, EndIntEn(1) = 1, TXFIFOIntEn(1) = 0, RXFIF
             -OIntEn(1) = 0, TXFIFOURIntEn(1) = 0, RXFIFOORIntEn(1) = 0
 132   1        
 133   1        /* enable global interrupt */
 134   1        //INTC->int_gmask = 0x01;
 135   1        
 136   1        /* set SPI interface timing */
 137   1        SPI_Clock_1M();
 138   1        
 139   1      
 140   1      
 141   1      }
 142          
 143          /**
 144           * @brief       IOConfig function
 145           *
 146           * @param       None
 147           *
 148           * @return      None
 149           *
 150           * @details     1. 
 151           */
 152          void IOConfig()
 153          {
 154   1        /* enable P0.0(MISO), P0.1(MOSI), P0.2 (SCLK), P0.3 (SS) function */
 155   1        Set_PA0_MISO();
 156   1        Set_PA1_MOSI();
 157   1        Set_PA2_SCLK();
 158   1        PORT_SetPAGPIO(BIT3); // PA3 as GPIO(SS)
 159   1        
 160   1        /* enable P0.0 input (MISO), P0.1 output (MOSI), P0.2 output (SCLK), P0.3 output (SS) */
 161   1        PORT_SetPAInput(BIT0);
 162   1        PORT_SetPAPushPull(BIT1 | BIT2 | BIT3);
 163   1        
 164   1        /* Set PC7 input as button */
 165   1        PORT_SetPCInput(BIT7);
 166   1      
 167   1        /* Set PD1. ,PD2.,PD3 output */
C51 COMPILER V9.60.0.0   MAIN                                                              03/13/2023 13:47:56 PAGE 4   

 168   1        PORT_SetPDPushPull(BIT1 | BIT2 | BIT3 );
 169   1        
 170   1        
 171   1       PD1 = 0; // LED_G1 On
 172   1        PD2 = 1 ; //LED_R Off
 173   1        PD3= 0;  // LED_G2  On
 174   1        
 175   1        PA3 =1; // SS
 176   1      }
 177          
 178          
 179          /**
 180           * @brief       CLKConfig function
 181           *
 182           * @param       None
 183           *
 184           * @return      None
 185           *
 186           * @details     1. 
 187           */
 188          void CLKConfig()
 189          { 
 190   1        /* enable GPIO clock */
 191   1        PORT_PAPBPCPD_Clock_Enable(); // enable GPIOA GPIOB GPIOC GPIOD clock
 192   1        
 193   1        /* enable SPI clock */
 194   1        En_SPI_clk();
 195   1        
 196   1      }
 197          
 198          void SPI_WriteByte( unsigned char data_)
 199          {
 200   1        SPI->trans_ctrl[3] = 0x01; // Write only   
 201   1        SPI->spi_dat = data_;
 202   1        SPI->spi_cmd = 0x02;
 203   1        delay();
 204   1        while( (SPI->int_stat & 0x10) == 0x10){}
 205   1        SPI->int_stat |= 0x10;
 206   1        SPI->spi_ctrl[0] = 0x06;
 207   1      }
 208          
 209          unsigned char SPI_ReadByte( unsigned char dummy)
 210          {
 211   1        unsigned char data_ =  0 ;
 212   1        SPI->trans_ctrl[3] = 0x02; // Read only   
 213   1        SPI->spi_dat = dummy;
 214   1        SPI->spi_cmd = 0x03;
 215   1        delay();
 216   1        while( (SPI->int_stat & 0x10) == 0x10){}
 217   1        SPI->int_stat |= 0x10;
 218   1        data_ =  SPI->spi_dat ;
 219   1        SPI->spi_ctrl[0] = 0x06;
 220   1          
 221   1        return data_;
 222   1      }
 223          
 224          
 225          
 226          /**
 227           * @brief       main function
 228           *
 229           * @param       None
C51 COMPILER V9.60.0.0   MAIN                                                              03/13/2023 13:47:56 PAGE 5   

 230           *
 231           * @return      None
 232           *
 233           * @details     1. 
 234           */
 235          int main (void)
 236          {
 237   1        CLKConfig();
 238   1        IOConfig();
 239   1        
 240   1        SPIMasterTransmitConfig();
 241   1      
 242   1        delay();
 243   1        
 244   1        while(1)
 245   1        {
 246   2            if( Get_PCx_input(7) == 0)   // PC7  = 0 , button down
 247   2            {
 248   3                  while(Get_PCx_input(7) == 0){}
 249   3                    
 250   3                  PD2 = 0 ; //LED_R On
 251   3              
 252   3                  // SPI Write and Read
 253   3                    
 254   3                  PA3 = 0; // Pull low PA3(SS)
 255   3        
 256   3                  SPI_WriteByte(0x90); //Write 0x90
 257   3                  SPI_WriteByte(0x00); //Write 0x00
 258   3                  SPI_WriteByte(0x00); //Write 0x00
 259   3                  SPI_WriteByte(0x00); //Write0x00
 260   3                    
 261   3                  spi_read_data[0] = SPI_ReadByte(0x11); //Read  (0x11 is Dummy Write)  
 262   3                  spi_read_data[1] = SPI_ReadByte(0x11); //Read  (0x11 is Dummy Write)
 263   3                  
 264   3                  PA3=1;// Pull high PA3(SS)
 265   3              
 266   3            }
 267   2            else
 268   2            {
 269   3                PD2 = 1 ; //LED_R Off
 270   3            }
 271   2        }
 272   1      }
 273          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    697    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =     10    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =      9    ----
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)
